package com.headwind.logistics.system.controller;


import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonGenerator;
import com.headwind.logistics.common.pojo.Coupon;
import com.headwind.logistics.common.pojo.Customer;
import com.headwind.logistics.common.util.LayuiUtil;
import com.headwind.logistics.common.util.RedisUtils;
import com.headwind.logistics.log.annotate.Log;
import com.headwind.logistics.system.dto.CouponCustomerUsedto;
import com.headwind.logistics.system.service.intl.CouponServiceIntl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author 桂祥宇
 * @Date 2020/7/17 0017 16:27
 * @Version 1.0
 * @DESCRIPTION 优惠券控制器层
 */
@Controller
public class CouponController {

    //优惠券业务逻辑层接口
    @Resource
    private CouponServiceIntl couponServiceIntl;

    /**
     * 查询所有优惠券
     * @param page 页码
     * @param limit 行数
     * @return
     */
    @GetMapping("/admin/system/queryAllCouponCustomerUsedto")
    @ResponseBody
    @Log("查询所有优惠券")
    public LayuiUtil queryAllCouponCustomerUsedto(Integer page,Integer limit){

        List<CouponCustomerUsedto> couponCustomerUsedtos=couponServiceIntl.queryAllCouponCustomerUsedto(page, limit);

        return LayuiUtil.data(couponServiceIntl.queryAllCouponCustomerUsedto(null,null).size(),couponCustomerUsedtos);
    }



    /**
     * 根据id删除优惠券
     * @param id
     * @return
     */
    @GetMapping("/admin/system/deleteCoupon")
    @ResponseBody
    @Log("根据id删除优惠券")
    public int deleteCoupon(Long id){

        int count =couponServiceIntl.deleteCoupon(id);
        return count;
    }

    /**
     * 查询用户信息
     * @return
     */
    @GetMapping("/admin/system/queryAllCustomer")
    @ResponseBody
    @Log("查询用户信息")
    public List<Customer> queryAllCustomer(){
        List<Customer> customers=couponServiceIntl.queryAllCustomer();

        return customers;
    }


    /**
     * 新增优惠券
     * @param coupon 优惠券对象
     * @return
     */
    @GetMapping("/admin/system/addCoupon")
    @ResponseBody
    @Log("新增优惠券")
    public int addCoupon(Coupon coupon){
        int count =couponServiceIntl.addCoupon(coupon);

        return  count;
    }

    @GetMapping("/admin/system/updateCustomer")
    @ResponseBody
    @Log("修改优惠券生效状态")
    public  int updateCustomer(int id){
        int count =couponServiceIntl.updateCustomer(id);
        return count;
    }
}
